﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace Presentation.Controls
{
    public static class FechaPublicacion
    {
        internal static System.Web.UI.WebControls.ListItem[] getLisItem()
        {
            ListItem[] lisItem = new ListItem[6];
            for (int i = 0; i <= 5; i++)
            {
                int addMonths = i - 2;
                lisItem[i] = new ListItem(DateTime.Now.AddMonths(addMonths).ToString("MMMM, yyyy"), "01/" + DateTime.Now.AddMonths(addMonths).Month + "/" + DateTime.Now.AddMonths(addMonths).Year);
            }
            return lisItem;
        }

        internal static ListItem createItem(DateTime dateTime)
        {
            return (new ListItem(dateTime.ToString("MMMM, yyyy"), "01/" + dateTime.Month + "/" + dateTime.Year));
        }

        internal static System.Web.UI.WebControls.ListItem[] getLisItem(string dateFormat)
        {
            if (dateFormat.Equals("yyyy"))
            { return getLisItemYear(dateFormat); }

            ListItem[] lisItem = new ListItem[6];
            for (int i = 0; i <= 5; i++)
            {
                int addMonths = i - 2;
                lisItem[i] = new ListItem(DateTime.Now.AddMonths(addMonths).ToString(dateFormat), "01/" + DateTime.Now.AddMonths(addMonths).Month + "/" + DateTime.Now.AddMonths(addMonths).Year);
            }
            return lisItem;
        }

        internal static System.Web.UI.WebControls.ListItem[] getLisItemYear(string dateFormat)
        {
            
            int year = 1970;
            int i = 0;
            int yearMax = DateTime.Now.Year + 10;
            int sizeArray = yearMax - year;
            ListItem[] lisItem = new ListItem[sizeArray];
            while(year<yearMax && i<sizeArray)
            {
                lisItem[i] = new ListItem(Convert.ToString(year + i), "01/01/" + Convert.ToString(year + i));
                i++;
            }
            return lisItem;
        }

        internal static ListItem createItem(DateTime dateTime, string dateFormat)
        {
            return (new ListItem(dateTime.ToString(dateFormat), "01/" + dateTime.Month + "/" + dateTime.Year));
        }

        internal static string getFechaFormatted(DateTime date)
        {
            return "01/" + date.Month.ToString() + "/" + date.Year.ToString();
        }

        internal static string getFechaFormattedYear(DateTime date)
        {
            return "01/01/" + date.Year.ToString();
        }
    }
}